package com.ebc.eservice.config.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.ebc.eservice.util.CurrentUser;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author: Joey
 * @Description:
 * @date:2022/9/21 14:21
 */

@Component
public class MyMetaObjectHandler  implements MetaObjectHandler {

    //todo 功能完善后 这里添加自动获取当前登录对象信息
    @Override
    public void insertFill(MetaObject metaObject) {
        CurrentUser user = new CurrentUser();
        this.setFieldValByName("createTime", LocalDateTime.now(),metaObject);
//        this.setFieldValByName("createId", user.getCurrentUser(),metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        CurrentUser user = new CurrentUser();
//        this.setFieldValByName("updateId", user.getCurrentUser(),metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(),metaObject);
    }
}
